package cn.rdq.iknesssystem.controller;

import cn.rdq.api.po.Drama;
import cn.rdq.api.vo.DramaVo;
import cn.rdq.common.CommonResult;
import cn.rdq.iknesssystem.service.DramaService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/drama")
public class DramaController {

    @Autowired
    private DramaService dramaService;

    @PostMapping("/list")
    public CommonResult dramaList(DramaVo dramaVo) {
        return CommonResult.success().pageSuccess(dramaService.dramaList(dramaVo));
    }

    @PostMapping("/save")
    public CommonResult save(@RequestBody Drama drama) {
        dramaService.saveDrama(drama);
        return CommonResult.success();
    }

    @PostMapping("/update")
    public CommonResult updateDrama(@RequestBody Drama drama) {
        drama.setUpdateTime(new Date());
        boolean update = dramaService.updateById(drama);
        return CommonResult.success();
    }

    @GetMapping("/queryOne")
    public CommonResult queryOne(DramaVo dramaVo) {
        Drama drama = dramaService.queryOne(dramaVo);
        return CommonResult.successObj(drama);
    }

    @GetMapping("/delete")
    public CommonResult delete(Long id) {
        boolean b = dramaService.removeById(id);
        return CommonResult.success();
    }

    @RequestMapping("/options")
    public CommonResult options() {
        return CommonResult.successObj(dramaService.dramaOptions());
    }
}
